class CreateDidilies < ActiveRecord::Migration
    def self.up
        create_table "didilies", :force => true do |t|
            t.column "user_id", :int
            t.column "to_id", :int
            t.column "to_title", :string, :limit => 1024, :null => false
            t.column "from_id", :int
            t.column "relationship_id", :int
            t.column "from_title", :string, :limit => 1024, :null => false
            t.column "created_at", :datetime
            t.column "updated_at", :datetime
        end
        
        add_index :didilies, :user_id
        add_index :didilies, :to_id
        add_index :didilies, :from_id
        add_index :didilies, :relationship_id
        
        execute "ALTER TABLE didilies ADD CONSTRAINT didilies_users_user_id_fkey FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE ON UPDATE CASCADE"
        execute "ALTER TABLE didilies ADD CONSTRAINT didilies_links_to_id_fkey FOREIGN KEY (to_id) REFERENCES links (id) ON DELETE CASCADE ON UPDATE CASCADE"
        execute "ALTER TABLE didilies ADD CONSTRAINT didilies_links_from_id_fkey FOREIGN KEY (from_id) REFERENCES links (id) ON DELETE CASCADE ON UPDATE CASCADE"
        execute "ALTER TABLE didilies ADD CONSTRAINT didilies_relationship_id_fkey FOREIGN KEY (relationship_id) REFERENCES relationships (id) ON DELETE CASCADE ON UPDATE CASCADE"
        
    end
    
    def self.down
        drop_table :didilies
    end
end
